

$(function () {

    // 缩小后的导航栏效果
    $('#caidaBtn').on('click', () => {
        $('.neir').slideToggle(500)
    })

    // 刷新首页
    $('#caida-nav li:eq(0) , .title-left , #title-right-nav li:eq(0)').on('click', function () {
        location.href = '/api'
    })

    // 返回顶部
    $("#fahui").hide();
    $(window).bind('scroll', function () {
        if ($(window).scrollTop() <= 200) {
            $("#fahui").hide();
        } else {
            $("#fahui").show();
        }
    });
    $("#fahui").bind("click", function () {
        $('html, body').animate({ scrollTop: 0 }, 200);
    });

    // get发送参数，主页文章详情
    $('.box-left-ul-h2').click(function (e) {
        let aid = 0
        let name = '未登录'
        if (window.location.search !== '') {
            let username = window.location.search.substring(10).split('&');
            name = username[0]
            aid = username[1].substring(7)
        }
        e.preventDefault();
        var v = $(this).attr('index')
        

        window.location = '/api/article/?id=' + v + '&' + 'aid=' + aid + '&' + 'username=' + name;

        // 访问量
        let fwl = $(this).next().text().replace(/\s/g,"")
        if (localStorage.getItem('token') !== null) {
           
            $.post('/api/article/fwl', { visit: fwl, id: v }, function (res) {
                if (res.status !== 0) {
                    return console.log(res.message);
                }
            })
        }



    })


    // 最新文章详情
    $('.box3-x').click(function (e) {
        let aid = 0
        let name = '未登录'
        if (window.location.search !== '') {
            let username = window.location.search.substring(10).split('&');
            name = username[0]
            aid = username[1].substring(7)
        }
        e.preventDefault();
        var v = $(this).text().replace(/\s/g, "").split("/?,");
        var _this = this;
        var index = _this.getAttribute("index");

        window.location = '/api/article/?id=' + index + '&' + 'aid=' + aid + '&' + 'username=' + name;
        // 访问量
        if (localStorage.getItem('token') !== null) {
            $.post('/api/article/fwl', { visit: v[1], id: index }, function (res) {
                if (res.status !== 0) {
                    return console.log(res.message);
                }
              
            })
            
        }

        


    })



    if (localStorage.getItem('token') == null) {
        $('.tcdl-tcdl').hide()
        $('.tcdl-dl').show()
    }

    // 退出登录
    $('.tcdl-tcdl').on('click', function () {
        location.replace("/api/users/render")
        window.localStorage.removeItem('token')
    })

    // 登录
    $('.tcdl-dl').on('click', function () {
        location.replace("/api/users/render")
    })



})